//
//  MyBigPhotoCollectionView.m
//  Day5_图片浏览
//
//  Created by apple on 16/5/17.
//  Copyright © 2016年 ljp. All rights reserved.
//

#import "MyBigPhotoCollectionView.h"
#import "MyPhotoCollectionViewCell.h"

@interface MyBigPhotoCollectionView ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end
@implementation MyBigPhotoCollectionView

- (instancetype)initWithFrame:(CGRect)frame {

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置单元格视图与四周间隙
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, BlockWidth);
    //设置单元格竖直间隙
    flowLayout.minimumLineSpacing = BlockWidth;
    //设置滑动方向为水平
    flowLayout.scrollDirection =     UICollectionViewScrollDirectionHorizontal;

    //设置单元格大小
    CGSize size = frame.size;
    size.height -= 64;
    flowLayout.itemSize = size;

    frame.size.width += BlockWidth;
    self = [super initWithFrame:frame collectionViewLayout:flowLayout];
    if (self) {
        self.pagingEnabled = YES;
        self.dataSource = self;

        //注册单元格类
        [self registerClass:[MyPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _urlArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    MyPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.url = _urlArray[indexPath.item];

    [cell backToOneScale];

    return cell;

}


@end
